# coding:utf-8

from lib.base import Base

from page.android import train_qunar_order_fill_page

__author__ = 'weixin.yuan'


class TrainQunarOrderFill(Base):
    """qunar订单"""
    def __init__(self, method_name):
        Base.__init__(self, method_name)

        """
        本页元素
        """
        self.qunar_fill_title = train_qunar_order_fill_page.elements['订单填写']
        self.shikebiao_btn = train_qunar_order_fill_page.elements['时刻表']
        self.shikebiao_title = train_qunar_order_fill_page.elements['时刻表title']
        self.gbxz_1 = train_qunar_order_fill_page.elements['支付后立即出票']
        self.gbxz_2 = train_qunar_order_fill_page.elements['支持退票改签']
        self.gbxz_3 = train_qunar_order_fill_page.elements['更多购票须知']
        self.gbxz_title = train_qunar_order_fill_page.elements['购票须知title']
        self.accept_no_seat = train_qunar_order_fill_page.elements['接受无座']
        self.tj_chengke_btn = train_qunar_order_fill_page.elements['添加乘客']
        self.xz_chengke_btn = train_qunar_order_fill_page.elements['选择乘客']
        self.bz_chengke_btn = train_qunar_order_fill_page.elements['添加/编辑乘客']
        self.yes_btn = train_qunar_order_fill_page.elements['确定添加乘客']
        self.tj_ertong_btn = train_qunar_order_fill_page.elements['添加儿童']
        self.lxr_btn = train_qunar_order_fill_page.elements['联系人']
        self.mobile_btn = train_qunar_order_fill_page.elements['手机号']
        self.mobile_input = train_qunar_order_fill_page.elements['通知出票信息']

        self.commit_btn = train_qunar_order_fill_page.elements['提交订单']
        self.go_on_btn = train_qunar_order_fill_page.elements['继续预订']
        self.payment_title1 = train_qunar_order_fill_page.elements['订单支付']
        self.payment_title2 = train_qunar_order_fill_page.elements['支付收银台']

        """
        外部页面元素
        """

    def test_qunar_order_fill(self):
        """qunar订单填写"""
        self.open_schema_android('6015')

        self.check(self.qunar_fill_title)

        self.click(self.shikebiao_btn)
        self.check(self.shikebiao_title)
        self.back()

        if self.is_exits(self.gbxz_1, times=3):
            self.click(self.gbxz_1)
            self.click(self.gbxz_title)
            self.back()

            self.click(self.gbxz_2)
            self.click(self.gbxz_title)
            self.back()

            self.click(self.gbxz_3)
            self.click(self.gbxz_title)
            self.back()

        self.click(self.accept_no_seat)
        self.click(self.accept_no_seat)  # 连续点击两次接受无座

        if self.is_exits(self.tj_ertong_btn, times=3):
            self.click(self.bz_chengke_btn)
            self.check(self.xz_chengke_btn)
            self.back()
        else:
            self.click(self.tj_chengke_btn)
            self.click(self.xz_chengke_btn)
            self.click(self.yes_btn)

        self.click(self.lxr_btn)
        self.click(self.mobile_btn)

        self.click(self.commit_btn)
        self.click(self.go_on_btn, is_necessary=False, times=10)
        # self.check(self.payment_title1)
        if not self.is_exits(self.payment_title1, times=90) and not self.is_exits(self.payment_title2):
            raise AssertionError('没有找到已支付和支付收银台title')
